package com.rocksdata.mc.ui.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ctz.commonframe.constant.DeviceInfo;
import com.ctz.commonframe.utils.GlideApp;
import com.rocksdata.mc.R;
import com.rocksdata.mc.entity.NewsInfo2;

/**
 * Created by 陈堂正 on 2017/5/12.
 */

public class NewsMultiImageHolder extends AbsNewsHolder<NewsInfo2> {
    private TextView tvTitle;
    private TextView tvOtherInfo;
    private ImageView ivImage1;
    private ImageView ivImage2;
    private ImageView ivImage3;

    NewsMultiImageHolder(View itemView) {
        super(itemView);
        tvTitle = itemView.findViewById(R.id.tv_news_title);
        tvOtherInfo = itemView.findViewById(R.id.tv_news_other_info);
        ivImage1 = itemView.findViewById(R.id.iv_news_image1);
        ivImage2 = itemView.findViewById(R.id.iv_news_image2);
        ivImage3 = itemView.findViewById(R.id.iv_news_image3);

        ViewGroup.LayoutParams imageParams1 = ivImage1.getLayoutParams();
        imageParams1.height = (DeviceInfo.screenWidth - 40) * 3 / 16 ;
        ivImage1.setLayoutParams(imageParams1);

        ViewGroup.LayoutParams imageParams2 = ivImage2.getLayoutParams();
        imageParams2.height = (DeviceInfo.screenWidth - 40) * 3 / 16 ;
        ivImage2.setLayoutParams(imageParams2);

        ViewGroup.LayoutParams imageParams3 = ivImage3.getLayoutParams();
        imageParams3.height = (DeviceInfo.screenWidth - 40) * 3 / 16 ;
        ivImage3.setLayoutParams(imageParams3);
    }

    @Override
    public void bindData(NewsInfo2 info) {
        tvTitle.setText(info.getTitle());
        tvOtherInfo.setText(info.getDepartmentName() + "  " + info.getPublishedTime());

        GlideApp.with(ivImage1.getContext()).load(info.getImgURL().get(0)).centerCrop().into(ivImage1);
        GlideApp.with(ivImage2.getContext()).load(info.getImgURL().get(1)).centerCrop().into(ivImage2);
        if(info.getImgURL().size() > 2) {
            GlideApp.with(ivImage3.getContext()).load(info.getImgURL().get(2)).centerCrop().into(ivImage3);
        }else{
            ivImage3.setVisibility(View.INVISIBLE);
        }
    }
}
